<?php 
	
	class Tag_Model {
				
		public function insertTag($type) {			
			$ret = mysql_query("INSERT INTO tag (type) VALUES ('$type')");			
			return $ret;
		}			
		
		public function getTagInfo($post_id) {
			$res = mysql_query("SELECT *
								FROM post_tag
								INNER JOIN tag
								ON tag_id=tag.ID
								WHERE post_id = $post_id") or die(mysql_error());
			return $res;
		}
		
		public function getTags($post_id) {
			$res = mysql_query("SELECT type
									FROM post
									INNER JOIN post_tag
									ON post_tag.post_id=post.ID
									INNER JOIN tag
									ON tag.ID=post_tag.tag_id
									INNER JOIN user
									ON user.ID=post.poster_id
									WHERE post_tag.post_id = $post_id") or die(mysql_error());
			return $res;
		}
		
		public function getTagInfoByType($type) {			
			$res = mysql_query("SELECT * FROM tag WHERE type='$type' LIMIT 1");			
			return $res;
		}
		
		public function insertPostTag($post_id, $tag_id) {						
			$ret = mysql_query("INSERT INTO post_tag (post_id, tag_id) VALUES ('$post_id', '$tag_id')") or die('mysql_error : '.mysql_error());			
			return $ret;
		}
	}


?>